all=run
cc=gcc
src_path=./src
inc_path=./inc
lib_path=./lib

inc=$(foreach item,$(inc_path),-I $(item))
lib=$(shell find $(lib_path) -name "lib*")
lib_l=$(foreach item,$(lib_path),-L$(item))
lib_a=$(foreach item,$(subst lib,,$(basename $(notdir $(filter %.a,$(lib))))),-l$(item))
lib_so=$(foreach item,$(subst lib,,$(basename $(notdir $(filter %.so,$(lib))))),-l$(item))

option=-Wall -O3 $(inc) $(lib_l) $(lib_a) $(lib_so)

src=$(shell find $(src_path) -name "*.c")
obj=$(patsubst ./src/%.c,./obj/%.o,$(src))

./obj/%.o:./src/%.c
	@mkdir -p $(dir $@)
	cc -c $^ -o $@ $(option)

workspace/exe:$(obj)
	@mkdir -p $(dir $@)
	cc $^ -o $@ $(option)

run:workspace/exe
	@./$<

debug:
	@echo $(inc)
	@echo $(lib)
	@echo $(lib_l)
	@echo $(lib_a)
	@echo $(lib_so)
	@echo $(option)
clean:
	@rm $(obj) $(workspace) -rf
.PHONY:debug clean
